/* spawn扩展 */
export default class spawnExtension extends StructureSpawn {
    // 孵化爬虫基本函数 自动赋予爬虫姓名、出生房间、所属shard、工种
    public hatchCreep(role:string,body:BodyPartConstant[],mem?:any):boolean{
        // 时间字符串化 取服务器时间后四位
        let timestr = Game.time.toString().substr(Game.time.toString().length - 4)
        // 爬虫角色字符串化
        let roleStr = `${role[0]}`
        // 取五位随机字符串
        let randomStr = Math.random().toString(36).substr(3)
        let creepName = `${roleStr}-${Math.round(Math.random()*99999)}-${Game.shard.name[0]}`
        // 重名查询
        if (Game.creeps[creepName]) return false
        // body整理
        let bodyData:BoostData = {}
        for (var b of body)
        {
            if (!bodyData[b]) bodyData[b] = {}
        }
        // 记忆整理
        var thisMem = {
            role:role,
            belong:this.room.name,
            shard:Game.shard.name,
            boostData:bodyData,
            working:false
        }
        // 额外记忆添加
        if (mem)
        {
            for (var i in mem)
            {
                thisMem[i] = mem[i]
            }
        }
        this.spawnCreep(body,creepName,{
            memory:thisMem})
        return true
    }

}